# -*- coding: utf-8 -*-
"""
    Data: 2022/6/14
    Time: 12:10
    Author: Driving
"""

from PyQt5.Qt import *
import sys
from resources.login import Ui_Form


class LoginPage(QWidget, Ui_Form):

    show_register_signal = pyqtSignal()
    check_login_signal = pyqtSignal(str, str)

    def __init__(self, parent=None, *args, **kwargs):
        super(LoginPage, self).__init__(parent, *args, **kwargs)
        self.setAttribute(Qt.WA_StyledBackground, True)  # 默认背景关闭，需要手动设置
        self.setupUi(self)
        self.setWindowTitle("Defect Detection System Login-Page")
        self.setWindowIcon(QIcon('./images/logo.png'))

        movie = QMovie(":/login/images/top_gif4.gif")
        movie.setScaledSize(QSize(600, 283))
        self.gif_label.setMovie(movie)
        movie.start()

        self.account_input_cb.setEditable(True)
        self.account_input_cb.setMaxCount(5)
        self.account_input_cb.addItem("admin")

    def show_register_page(self):
        self.show_register_signal.emit()

    def judge_login_enable(self):
        account_txt = self.account_input_cb.currentText()
        pw_txt = self.pw_input_le.text()
        if len(account_txt) > 0 and len(pw_txt) > 0:
            self.login_input_btn.setEnabled(True)
        else:
            self.login_input_btn.setEnabled(False)

    def check_login(self):
        account_txt = self.account_input_cb.currentText()
        pw_txt = self.pw_input_le.text()
        self.check_login_signal.emit(account_txt, pw_txt)

    def remember_pw(self, checked):
        if not checked:
            self.autologin_cb.setChecked(False)

    def auto_login(self, checked):
        if checked:
            self.remember_cb.setChecked(True)

    @staticmethod
    def open_web():
        link = "https://gitee.com/zihaodl/detect_app"
        QDesktopServices.openUrl(QUrl(link))


if __name__ == '__main__':

    app = QApplication(sys.argv)
    window = LoginPage()

    window.show()
    sys.exit(app.exec_())